<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title>订单明细</title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bindgrid();
                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                        });
                    </script>

                    <script type="text/javascript">
                        var selectedFileList = [];//已选文件列表
                        var succsessCount = 0;//上传成功文件个数
                        var errorCount = 0;//上传失败文件个数
                        /************文件处理部分*************/


                        /**
                         *文件框改变事件
                         */
                        function changeFile() {
                            var files = $("#uploadpicker").prop("files");
                            $
                                .each(
                                    files,
                                    function (index, item) {
                                        let choiseFile = $("#checkfileList>li");
                                        if (choiseFile.length > 0) {//文件去重
                                            let count = 0;
                                            $.each(choiseFile, function (index1, item1) {
                                                if (item.name == item1.innerText) {
                                                    count++;
                                                }
                                            });
                                            if (count == 0) {
                                                if (checkFileLength(item.size)) {
                                                    if (item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                        alert('文件名不能包含&、\\、空格等特殊字符！');
                                                        return;
                                                    }
                                                    $("#checkfileList")
                                                        .append(
                                                            "<li class=\"fileinfo\">"
                                                            + item.name
                                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                            + item.name
                                                            + "')\">删除</a>"
                                                            + "</li>");
                                                    selectedFileList.push(item);
                                                    AddMoushover();
                                                }
                                            }
                                        } else {
                                            if (checkFileLength(item.size)) {
                                                if (item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                    alert('文件名不能包含&、\\、空格等特殊字符！');
                                                    return;
                                                }
                                                $("#checkfileList")
                                                    .append(
                                                        "<li class=\"fileinfo\">"
                                                        + item.name
                                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                        + item.name
                                                        + "')\">删除</a>"
                                                        + "</li>");
                                                selectedFileList.push(item);
                                                AddMoushover();
                                            }
                                        }
                                    });
                        }

                        /**
                         *    判断文件是否超过限制大小
                         * @param fileLen
                         * @returns {boolean}
                         */
                        function checkFileLength(fileLen) {
                            if (fileLen > 102400000) {
                                $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                                return false;
                            }
                            return true;
                        }

                        /**
                         * //添加鼠标经过事件，鼠标划过时显示“删除”
                         * @constructor
                         */
                        function AddMoushover() {
                            $(".fileinfo").hover(function () {
                                $(this).find("a").last().css("display", "");
                            }, function () {
                                $(this).find("a").last().css("display", "none");
                            });
                        }

                        /**
                         *  移除已选择的文件
                         */

                        function RemoveFile(obj, fileId) {
                            $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                                if (e) {
                                    let index = $("#checkfileList>li").index($(obj).parent());
                                    selectedFileList.splice(index, 1);
                                    $(obj).parent().remove();

                                    $.ajax({
                                        type: "post",
                                        url: 'file/deleteFile?fileId=' + fileId,
                                        success: function (data) {
                                            $.messager.alert('消息', data);
                                        },
                                        error: function (XMLHttpRequest, textStatus,
                                            errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    });

                                }
                            });
                        }

                        /**
                         * 取得该条数据所属的文件列表
                         * @param row
                         */
                        function getFileList(id, status) {
                            $.ajax({
                                type: "post",
                                url: "file/getFileList",
                                data: {
                                    fileTable: "purchase_six_costs_orders_lines",
                                    fileRow: id
                                },
                                success: function (data) {
                                    const dataArray = eval(data);
                                    initFile(dataArray, status);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        /**
                         * 初始化该条数据的文件列表
                         * @param dataArray
                         */
                        function initFile(dataArray, status) {
                            $("#checkfileList").empty();
                            // 			sselectedFileNameList = [];
                            selectedFileList = [];
                            dataArray
                                .forEach(function (e, i, a) {
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                            + e.FILE_ID
                                            + "')\">"
                                            + e.FILE_NAME
                                            + "</a>"
                                            + (status > 0 ? '' : "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                + e.FILE_ID + "')\">删除</a>")
                                            + "</li>");
                                    if (status > 0) {
                                    } else {
                                        AddMoushover();
                                    }
                                });
                        }


                        // 文件下载
                        function downloadFile(fileName, fileRow) {
                            let url = 'api/file/download?id=' + fileRow
                            let xhr = new XMLHttpRequest()
                            xhr.open('GET', url, true)
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function (data) {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = fileName
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                } else {

                                }
                            }
                            xhr.send()
                        }
                    </script>
                    <script>
                        function del(node) {
                            $.ajax({
                                type: "delete",
                                url: 'purchase/six/costs/orders/lines/delete?' + 'lineId=' + node.lineId,
                                //                dataType: "xml",				
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#addWindow').window('close');
                                    selectList();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }
                        function back(node) {
                            $.ajax({
                                type: "get",
                                url: 'purchase/six/costs/orders/lines/back?' + 'lineId=' + node.lineId,
                                //                dataType: "xml",				
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#addWindow').window('close');
                                    selectList();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function save(status) {
                            if (!$('#fm').form('validate')) {
                                return;
                            }
                            var row = $('#dg').datagrid('getSelected');
                            var model = { lineId: $('#lineId').textbox('getValue'), purId: $('#purId').textbox('getValue'), deliveryNo: $('#deliveryNo').textbox('getValue'), sapOrderNo: $('#sapOrderNo').textbox('getValue'), contractName: $('#contractName').textbox('getValue'), contractCode: $('#contractCode').textbox('getValue'), deliveryType: $('#deliveryType').textbox('getValue'), deliveryTypeDesc: $('#deliveryTypeDesc').textbox('getValue'), costType: $('#costType').textbox('getValue'), costAmount: $('#costAmount').textbox('getValue'), costExtaxAmount: $('#costExtaxAmount').textbox('getValue'), costCurreny: $('#costCurreny').textbox('getValue'), costUnitPrice: $('#costUnitPrice').textbox('getValue'), costUnitCureny: $('#costUnitCureny').textbox('getValue'), costSupplyCode: $('#costSupplyCode').textbox('getValue'), costSupplyName: $('#costSupplyName').textbox('getValue'), createId: $('#createId').textbox('getValue'), createName: $('#createName').textbox('getValue'), createTime: $('#createTime').textbox('getValue'), updateId: $('#updateId').textbox('getValue'), updateName: $('#updateName').textbox('getValue'), updateTime: $('#updateTime').textbox('getValue'), deptName: $('#deptName').textbox('getValue'), status: $('#status').textbox('getValue'), deptId: $('#deptId').textbox('getValue'), factoryCode: $('#factoryCode').textbox('getValue'), materialCode: $('#materialCode').textbox('getValue'), materialName: $('#materialName').textbox('getValue'), signQuantity: $('#signQuantity').textbox('getValue'), saleOrderNo: $('#saleOrderNo').textbox('getValue'), saleOrderLineNo: $('#saleOrderLineNo').textbox('getValue'), materialGropCode: $('#materialGropCode').textbox('getValue'), custCode: $('#custCode').textbox('getValue'), custName: $('#custName').textbox('getValue'), vkorg: $('#vkorg').textbox('getValue') };
                            model.status = '0';
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'purchase/six/costs/orders/lines/save',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    if (data.code != 60200) {
                                    } else {
                                        saveAttch(data.data, row.id, status)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })

                        }

                        function commit(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'purchase/six/costs/orders/lines/commit',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                        $('#addWindow').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         * 保存附件
                         */
                        function saveAttch(row, rowId, action) {
                            let saveNum = 0
                            if (selectedFileList.length > 0) {
                                $.each(selectedFileList, function (index, item) {
                                    showFilediv();
                                    var dataform = new FormData();
                                    dataform.append("file", item);
                                    var xmlhttp = null;
                                    if (window.XMLHttpRequest) {// code for all new browsers
                                        xmlhttp = new XMLHttpRequest();
                                    } else if (window.ActiveXObject) {// code for IE5 and IE6
                                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    if (xmlhttp != null) {
                                        xmlhttp.open("POST", "api/file/springUpload?fileRow=" + rowId
                                            + "&fileTable=purchase_six_costs_orders_lines&fileName="
                                            + item.name, true);
                                        xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                                        xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                                        xmlhttp.send(dataform);
                                        xmlhttp.onreadystatechange = callbackMethods;
                                    } else {
                                        alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                                    }

                                    function callbackMethods() {
                                        if (xmlhttp.readyState == 4) {
                                            if (xmlhttp.status == 200) {
                                                saveNum += 1
                                                if (saveNum == selectedFileList.length) {
                                                    hideFilediv();
                                                    if ('1' == action) {
                                                        commit(row)
                                                    } else {
                                                        $.messager.alert('消息', '保存成功！');
                                                        selectList();
                                                        $('#addWindow').window('close');
                                                    }
                                                }
                                            }
                                        } else {
                                            if (xmlhttp.status == 500) {
                                            }
                                        }
                                    }
                                });
                            } else {
                                if ('1' == action) {
                                    commit(row)
                                } else {
                                    $.messager.alert('消息', '保存成功！');
                                    selectList();
                                    $('#addWindow').window('close');
                                }
                            }
                        }

                        function editrow(row) {
                            //编辑用户
                            var row = $('#dg').datagrid('getSelected');
                            if (row) {
                                $('#addWindow').window('open');
                                $('#fm').form('load', row);
                                initBtn(row.status);

                            } else {
                                $.messager.alert('消息', '请选中一条数据');
                            }
                        }
                    </script>
                    <script>

                        function initBtn(status) {
                            if (status == '0') {
                                $('#tabs').tabs({
                                    tools: [{
                                        text: '保存',
                                        iconCls: 'icon-save',
                                        handler: function () {
                                            save('0');
                                        }
                                    }, {
                                        text: '提交',
                                        iconCls: 'icon-ok',
                                        handler: function () {
                                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                function (r) {
                                                    if (r) {
                                                        save('1');
                                                    }
                                                });
                                        }
                                    }]
                                })
                            } else {
                                $('#tabs').tabs({
                                    tools: null
                                })
                            }
                        }
                        /**
                                                         *  按条件查询报价列表
                                                         */
                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var status = $('#status').combobox('getValue');
                            var dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : '',
                                status: status ? status : ''
                            });
                        }

                        function bindgrid() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var status = $('#status').combobox('getValue');
                            $('#dg').datagrid({
                                title: '',
                                queryParams: {
                                    startTime: startTime,
                                    endTime: endTime,
                                    status: status
                                },
                                url: "purchase/six/costs/orders/lines/selectList",
                                iconCls: 'icon-application',
                                width: getWidth(0.98),
                                height: 400,
                                nowrap: true,
                                filterDelay: 0,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                clientPaging: false,
                                remoteFilter: true,
                                singleSelect: true,
                                pagination: true,
                                remoteSort: true,
                                frozenColumns: [[{
                                    field: 'lineId',
                                    title: '费用采购行项目ID',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'purId',
                                    title: '费用采购ID',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'deliveryNo',
                                    title: '交货单号',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'sapOrderNo',
                                    title: 'SAP采购订单号',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                },]],
                                columns: [[{
                                    field: 'contractName',
                                    title: '销售合同名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'contractCode',
                                    title: '销售合同号',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'deliveryType',
                                    title: '交货单类型',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'deliveryTypeDesc',
                                    title: '交货单类型描述',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costType',
                                    title: '费用类型',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costAmount',
                                    title: '费用总额',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costExtaxAmount',
                                    title: '不含税费用',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costCurreny',
                                    title: '费用货币',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costUnitPrice',
                                    title: '费用单价',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costUnitCureny',
                                    title: '费用单价货币',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costSupplyCode',
                                    title: '费用供应商code',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'costSupplyName',
                                    title: '费用供应商名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createId',
                                    title: '创建人id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createName',
                                    title: '创建人姓名',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createTime',
                                    title: '创建时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateId',
                                    title: '更新人id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateName',
                                    title: '更新人姓名',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateTime',
                                    title: '更新时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'deptName',
                                    title: '部门名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'status',
                                    title: '订单状态',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        let status = val ? val : '';
                                        return unescape(status == '0' ? '待提交' : '已提交');
                                    }
                                    // }, {
                                    //     field: 'deptId',
                                    //     title: '部门id',
                                    //     sortable: true,
                                    //     hidden: true,
                                    //     formatter: function (val, rec) {
                                    //         return val ? unescape(val) : '';
                                    //     }
                                }, {
                                    field: 'factoryCode',
                                    title: '工厂代码',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'materialCode',
                                    title: '物料编码',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'materialName',
                                    title: '物料名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'signQuantity',
                                    title: '签收数量',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'saleOrderNo',
                                    title: '销售订单',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'saleOrderLineNo',
                                    title: '销售订单行项目',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'materialGropCode',
                                    title: '物料组',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'custCode',
                                    title: '客户编码',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'custName',
                                    title: '客户名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'vkorg',
                                    title: '销售组织',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }]],
                                toolbar: [
                                    //     {
                                    //     text: '增加',
                                    //     iconCls: 'icon-add',
                                    //     handler: function () {
                                    //         $('#dg').datagrid('clearSelections');
                                    //         $('#fm').form('clear');
                                    //         $('#addWindow').window('open');
                                    //         initFile([]);
                                    //         initBtn('0');
                                    //         $('#tabs').tabs('select', 0)
                                    //     }
                                    // },
                                    //     '-',
                                    // {
                                    //     text: '编辑',
                                    //     iconCls: 'icon-edit',
                                    //     handler: function () {
                                    //         //编辑用户
                                    //         var row = $('#dg').datagrid('getSelected');
                                    //         if (row) {
                                    //             editrow(row)
                                    //         } else {
                                    //             $.messager.alert('消息', '请选中一条数据');
                                    //         }
                                    //     }
                                    // },
                                    //     '-',
                                    // {
                                    //     text: '删除',
                                    //     iconCls: 'icon-cancel',
                                    //     handler: function () {
                                    //         var row = $('#dg').datagrid('getSelected');
                                    //         if (row) {
                                    //             if (row.status > 0) {
                                    //                 $.messager.alert('消息', '已提交，不可删除！');
                                    //                 return;
                                    //             }
                                    //             $.messager.confirm('提示', '确定要删除这个吗?', function (r) {
                                    //                 if (r) {
                                    //                     del(row);
                                    //                 }
                                    //             });
                                    //         } else {
                                    //             $.messager.alert('消息', '请选中一条数据');
                                    //         }
                                    //     }
                                    // },
                                    //     '-',
                                    // {
                                    //     text: '撤回',
                                    //     iconCls: 'icon-cancel',
                                    //     handler: function () {
                                    //         var row = $('#dg').datagrid('getSelected');
                                    //         if (row) {
                                    //             if (row.status > 0) {
                                    //                 $.messager.alert('消息', '已提交，不可删除！');
                                    //                 return;
                                    //             }
                                    //             $.messager.confirm('提示', '确定要撤回这个吗?', function (r) {
                                    //                 if (r) {
                                    //                     back(row);
                                    //                 }
                                    //             });
                                    //         } else {
                                    //             $.messager.alert('消息', '请选中一条数据');
                                    //         }
                                    //     }
                                    // }
                                ],
                                onLoadSuccess: function () {
                                },
                                onDblClickRow: function () {
                                    var row = $('#dg').datagrid('getSelected');
                                    // editrow(row);
                                }
                            });
                            $('#dg').datagrid('enableFilter');
                        }


                        // 导出为Excel
                        function exportList() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            let status = $('#status').combobox('getValue')
                            var form = [];
                            form.push('startTime=' + (startTime ? startTime : ''));
                            form.push('endTime=' + (endTime ? endTime : ''));
                            form.push('status=' + (status ? status : ''));
                            let url = "api/purchase/six/costs/orders/lines/export"
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                            xhr.setRequestHeader('token', localStorage.getItem('token'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = '询价供应商' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
        height: 15px;
    }*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label>
                                <input class="easyui-combobox" id="status" name="status" style="width: 80px;"
                                    data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待提交',
							value: '0',
							selected:true
						},{
							label: '已提交',
							value: '1'
						}]">
                                </select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                    onclick="selectList()">查询</a> <a id="export" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-export'"
                                    onclick="exportList()">导出</a>
                        </div>

                        <table id="dg"></table>

                        <div id="addWindow" class="easyui-window" closed="true" modal="true" title="详细信息"
                            style="width: 700px; height: 400px; padding: 5px 5px">
                            <div id="tabs" class="easyui-tabs" style="width: 650px; height: 350px">
                                <div title="基本信息" style="padding: 5px;">
                                    <form id="fm" class="ssec-form">
                                        <table class="table">
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用采购行项目ID：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="lineId" name="lineId" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用采购ID：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="purId" name="purId" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">交货单号：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="deliveryNo" name="deliveryNo" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">SAP采购订单号：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="sapOrderNo" name="sapOrderNo" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">销售合同名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="contractName" name="contractName"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">销售合同号：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="contractCode" name="contractCode"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">交货单类型：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="deliveryType" name="deliveryType"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">交货单类型描述：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="deliveryTypeDesc" name="deliveryTypeDesc"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用类型：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costType" name="costType" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用总额：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costAmount" name="costAmount" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">不含税费用：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costExtaxAmount" name="costExtaxAmount"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用货币：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costCurreny" name="costCurreny"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用单价：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costUnitPrice" name="costUnitPrice"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用单价货币：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costUnitCureny" name="costUnitCureny"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用供应商code：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costSupplyCode" name="costSupplyCode"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">费用供应商名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="costSupplyName" name="costSupplyName"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">创建人id：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="createId" name="createId" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">创建人姓名：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="createName" name="createName" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">创建时间：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="createTime" name="createTime" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">更新人id：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="updateId" name="updateId" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">更新人姓名：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="updateName" name="updateName" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">更新时间：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="updateTime" name="updateTime" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">部门名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="deptName" name="deptName" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">订单状态：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="status" name="status" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">部门id：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="deptId" name="deptId" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">工厂代码：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="factoryCode" name="factoryCode"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">物料编码：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="materialCode" name="materialCode"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">物料名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="materialName" name="materialName"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">签收数量：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="signQuantity" name="signQuantity"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">销售订单：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="saleOrderNo" name="saleOrderNo"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">销售订单行项目：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="saleOrderLineNo" name="saleOrderLineNo"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">物料组：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="materialGropCode" name="materialGropCode"
                                                            class="easyui-textbox" data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">客户编码：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="custCode" name="custCode" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">客户名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="custName" name="custName" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">销售组织：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="vkorg" name="vkorg" class="easyui-textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                        <!-- <div style="padding: 5px; text-align: right;">
                                            <a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
                                        </div> -->
                                    </form>
                                </div>
                                <div title="附件" style="padding: 5px;">
                                    <table>
                                        <tr>
                                            <td colspan="3"><input type="button" id="uploadbtn" value="选择文件..." />
                                                <input type="file" id="uploadpicker" accept="" onchange="changeFile()"
                                                    multiple style="display: none;" />
                                                <span>（文件名称不能包含斜杠、空格、&等特殊字符）</span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><label style="width: 40%; text-align: right;">附件下载：</label>
                                                <ul id="checkfileList"></ul>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
        </body>

        </html>